#include "pch.h"

Timer::Timer()
{
    // Initialize Variables
    startTicks = 0;
    stopTicks = 0;
    paused = false;
    started = false;
}

void Timer::Start()
{
    // Start the Timer
    started = true;

    // Unpause Timer
    paused = false;

    // Get Time
    startTicks = SDL_GetTicks();
}

void Timer::Stop()
{
    // Stop the Timer
    started = false;

    // Unpause Timer
    paused = false;
}

int Timer::getTicks()
{
    // If Timer is Running
    if (started == true)
    {
        // If Timer is Paused
        if (paused == true)
        {
            return stopTicks;
        }
        else
        {
            // Return the Current Time Minus the Start Time
            return (SDL_GetTicks() - startTicks);
        }
    }
    else
    {
        // If Timer is Not Running
        return 0;
    }
}

void Timer::Pause()
{
    // If Timer is Running and Not Paused
    if (started == true && paused == false)
    {
        // Pause the Timer
        paused = true;

        // Calculate the Paused Ticks
        stopTicks = SDL_GetTicks() - startTicks;
    }
}

void Timer::Unpause()
{
    // If Timer is Paused
    if (paused == true)
    {
        // Unpause the Timer
        paused = false;

        // Calculate the Unpaused Ticks
        startTicks = SDL_GetTicks() - stopTicks;

        // Reset Ticks
        stopTicks = 0;
    }
}

bool Timer::isStarted()
{
    return started;
}

bool Timer::isPaused()
{
    return paused;
}
